function   imp = irf_given_shocks(    current_model , years_simulation,  w,  leverage,  dB_vec, dN_vec )

disp(  [  '----------------- Generating the impulse response function for a ', current_model.par.model_name, ' model --------------------'   ]  )

par = current_model.par;
% Find the correct scaling for the credit spread. 
w_dim = kron(ones(par.N_lambda,1), par.w_grid );
lambda_dim = kron(par.lambda_grid, ones(par.N_w,1));

fit_a_function = @(values_matrix)  scatteredInterpolant(w_dim,    lambda_dim ,  reshape( values_matrix, par.N_w*par.N_lambda, 1 ),   'linear')  ;

m = simulation_results_output(current_model);
spread_fitted = fit_a_function(current_model.credit_spread);
avg_spread_before_normalization = mean( spread_fitted(m.w,m.lambda) ) ;
spread_fitted = fit_a_function(current_model.credit_spread/avg_spread_before_normalization);   % Re-adjust with the average
lvg_fitted = fit_a_function( current_model.xK_matrix );

solve_leverage_fun = @(lambda)  lvg_fitted(w,lambda) - leverage ;
opt_solver = optimset('Display','off');
[lambda, e] = fsolve( solve_leverage_fun,  (par.lambda_L+par.lambda_H)/2, opt_solver  );

lambda= max(min(lambda,par.lambda_H), par.lambda_L);
if( lambda<=par.lambda_L || lambda>=par.lambda_H || sum(abs(e))>10^(-5) )
    disp(  ['Error in solving the appropriate lambda! lambda=',num2str(lambda)] );
else
    disp( ['Initial lambda=', num2str(lambda)]  )
end

dt=par.dt;
N_sim = round(years_simulation/dt);
new_w_mutiplier = 1.1;
% Then start the simulation. 
sim = simulate( w, lambda, dB_vec, dN_vec,  years_simulation, current_model,  par  );
sim_pre_recap = sim.results;
sim_pre_recap.credit_spread = spread_fitted( sim_pre_recap.w,   sim_pre_recap.lambda );

sim = simulate( w*new_w_mutiplier, lambda, dB_vec, dN_vec,  years_simulation, current_model,  par  );
sim_post_recap = sim.results;
sim_post_recap.credit_spread = spread_fitted( sim_post_recap.w,   sim_post_recap.lambda );

% Impulse responses
w_impulse = sim_post_recap.w ./ sim_pre_recap.w - 1;
cs_impulse =  sim_post_recap.credit_spread ./  sim_pre_recap.credit_spread -1;
output_impulse =   sim_post_recap.productivity ./ sim_pre_recap.productivity -1  ;
output_pre =   sim_pre_recap.GDP;
output_post =   sim_post_recap.GDP  ;
bank_credit_impulse = sim_post_recap.bank_credit ./ sim_pre_recap.bank_credit - 1;

imp.w_impulse = w_impulse;
imp.cs_impulse = cs_impulse;
imp.output_impulse = output_impulse;
imp.output_pre = output_pre;
imp.output_post = output_post;
imp.bank_credit_impulse = bank_credit_impulse;
imp.lambda_init = lambda;



